package com.campus.wall;

import android.annotation.SuppressLint;
import android.content.Intent;

import com.campus.wall.base.BaseMvpActivity;
import com.campus.wall.contract.LoginContract;
import com.campus.wall.presenter.LoginPresenter;
import com.campus.wall.ui.FirstAcActivity;
import com.campus.wall.ui.MainActivity;
import com.self.baseutile.Constants;
import com.self.baseutile.MRWApplication;
import com.self.baseutile.components.CleanableEditText;
import com.self.baseutile.components.ToastUtils;

import butterknife.BindView;
import butterknife.OnClick;


public class LoginActivity extends BaseMvpActivity<LoginPresenter> implements LoginContract.View {


    @BindView(R.id.member_pass)
    CleanableEditText member_pass;
    @BindView(R.id.member_acccount)
    CleanableEditText member_acccount;

    @Override
    public int getLayoutId() {
        return R.layout.activity_login;
    }

    @SuppressLint("HandlerLeak")
    @Override
    public void initView() {

        mPresenter = new LoginPresenter(this);
        mPresenter.attachView(this);

    }


    @OnClick(R.id.login_btn)
    void Login(){
        if (getUsername().isEmpty() ) {
            ToastUtils.Warnshow("请输入学生账号");
            return;
        }
        if (getPassword().isEmpty() ) {
               ToastUtils.Warnshow("请输入登陆密码");
            return;
        }
        mPresenter.login(getUsername(),getPassword());
    }
    /**
     * @return 帐号
     */
    private String getUsername() {
        return member_acccount.getText().toString().trim();
    }

    /**
     * @return 密码
     */
    private String getPassword() {
        return member_pass.getText().toString().trim();
    }

    /**
     * @return 登陆成功
     */
    @Override
    public void onSuccess() {
        startActivity(new Intent(this, FirstAcActivity.class));
        finish();
    }




}
